package org.hqs.department.service;

import org.hqs.department.mapper.DepartmentMapper;
import org.hqs.department.pojo.Department;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

//@Service
//public class DepartmentService {
//
//    @Autowired
//    private DepartmentMapper departmentMapper;
//
//    public Department queryDepartmentById(Long departmentId) {
//        // 1.查询订单
//        Department department = departmentMapper.getDepartmentById(departmentId);
////        // 2.用Feign远程调用
////        User user = userClient.findById(order.getUserId());
////        // 3.封装user到Order
////        order.setUser(user);
//        // 4.返回
//        return department;
//    }
//}

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DepartmentService {

    @Autowired
    private final DepartmentMapper departmentMapper;

    @Autowired
    public DepartmentService(DepartmentMapper departmentMapper) {
        this.departmentMapper = departmentMapper;
    }

    public List<Department> getAllDepartments() {
        return departmentMapper.getAllDepartments();
    }

    public Department getDepartmentById(Long id) {
        return departmentMapper.getDepartmentById(id);
    }

    public int saveDepartment(Department department) {
        return departmentMapper.insertDepartment(department);
    }

    public int updateDepartment(Department department) {
        return departmentMapper.updateDepartment(department);
    }

    public int deleteDepartment(Long id) {
        return departmentMapper.deleteDepartment(id);
    }
}



